//
//  LFBReadTopTenArticleCell.m
//  ONE
//
//  Created by dllo on 16/6/7.
//  Copyright © 2016年 GroupNine. All rights reserved.
//

#import "LFBReadTopTenArticleCell.h"
#import "LFBTopTenArticleModel.h"

NSString *const kLFBTopTenArticleCellID = @"LFBTopTenArticleCellID";

@interface LFBReadTopTenArticleCell ()

/** 数字label */
@property (nonatomic, strong) UILabel *numberLabel;

/** 标题label */
@property (nonatomic, strong) UILabel *titleLabel;

/** 作者label */
@property (nonatomic, strong) UILabel *authorLabel;

/** 内容label */
@property (nonatomic, strong) UILabel *contentLabel;

@end

@implementation LFBReadTopTenArticleCell

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self createTopTenACell];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createTopTenACell];
    }
    return self;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        [self createTopTenACell];
    }
    
    return self;
}

#pragma mark --创建轮播图内容cell
- (void)createTopTenACell
{
    if (_titleLabel) {
        return;
    }
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    _numberLabel = [UILabel new];
    _numberLabel.textColor = [UIColor whiteColor];
    _numberLabel.font = [UIFont italicSystemFontOfSize:14];
    // //设置当视图要变大时，视图的放大改变方式，是水平放大还是垂直放大，并返回一个优先权
    [_numberLabel setContentHuggingPriority:251 forAxis:UILayoutConstraintAxisHorizontal];
    [self.contentView addSubview:_numberLabel];
    [_numberLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(8);
        make.left.equalTo(self.contentView).offset(36);
    }];
    
    _titleLabel = [UILabel new];
    _titleLabel.textColor = [UIColor whiteColor];
    _titleLabel.font = BoldFontWithSize(18);
    _titleLabel.numberOfLines = 2;
    [self.contentView addSubview:_titleLabel];
    [_titleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_numberLabel);
        make.left.equalTo(_numberLabel.right).offset(8);
        make.right.equalTo(self.contentView).offset(-36);
    }];
    
    _authorLabel = [UILabel new];
    _authorLabel.textColor = [UIColor whiteColor];
    _authorLabel.font = FontWithSize(12);
    [self.contentView addSubview:_authorLabel];
    [_authorLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLabel.bottom).offset(8);
        make.left.right.equalTo(_titleLabel);
    }];
    
    _contentLabel = [UILabel new];
    _contentLabel.textColor = [UIColor whiteColor];
    _contentLabel.numberOfLines = 2;
    _contentLabel.font = FontWithSize(13);
    [self.contentView addSubview:_contentLabel];
    [_contentLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_authorLabel.bottom).offset(8);
        make.left.right.equalTo(_titleLabel);
        make.bottom.equalTo(self.contentView).offset(-30);
    }];
}

#pragma mark --设置cell
- (void)configureCellWithTopTenArticleModel:(LFBTopTenArticleModel *)model atIndexPath:(NSIndexPath *)indexPath
{
    _numberLabel.text = [@(indexPath.row + 1) stringValue];
    _titleLabel.text = model.title;
    _authorLabel.text = model.author;
    _contentLabel.text = model.introduction;
}

@end
